// handler.js is a demo for handler function.
// event: 客户端传递过来参数，如：{num1:10,num2:20}
let myHandler = function (event, context, callback, logger) {
    let res = new context.HTTPResponse({}, {}, "application/json", "200");

    // 假设event对象包含两个数值属性num1和num2
    let num1;
    let num2;
    if (event.body) {
        var _body = JSON.parse(event.body);
        num1 = _body.num1;
        num2 = _body.num2;
    } else {
        num1 = event.num1;
        num2 = event.num2;
    }

    // 计算两个数的和
    let sum = num1 + num2;
    // send info log
    logger.info(sum + '=' + num1 + '+' + num2);
    // 设置响应体
    res.body = {
        "result": sum
    };

    // send response
    callback(res);
};

module.exports.myHandler = myHandler;